home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 October / The Sunday Times - The Month 2004-10.iso / pc / assets / bespoke / kids / power.swf / scripts / frame_5 / DoAction.as
Text File  |  2004-09-02  |  5KB  |  232 lines

  1. function levelObj(shape, rSpeed, zSpeed, levelTime, levelBonus)
  2. {
  3.    this.shape = shape;
  4.    this.rSpeed = rSpeed;
  5.    this.zSpeed = zSpeed;
  6.    this.levelTime = levelTime;
  7.    this.levelBonus = levelBonus;
  8. }
  9. function startLevel(num)
  10. {
  11.    levelScore = 0;
  12.    pcount = 0;
  13.    popList = new Array();
  14.    popsLeft = 0;
  15.    countdownTimer.setTimer(levels[currLevel].levelTime);
  16.    txtLevelTotal = levels.length;
  17.    txtLevelCurrent = currLevel + 1;
  18.    if(levels[currLevel].shape == 1)
  19.    {
  20.       fillPopGrid();
  21.    }
  22.    else if(levels[currLevel].shape == 2)
  23.    {
  24.       fillPopWave();
  25.    }
  26.    else if(levels[currLevel].shape == 3)
  27.    {
  28.       fillPopRings();
  29.    }
  30.    else if(levels[currLevel].shape == 4)
  31.    {
  32.       fillPopSpiro();
  33.    }
  34.    pcount = 0;
  35.    gotoAndPlay(9);
  36. }
  37. function resetGame()
  38. {
  39.    currLevel = 0;
  40.    gameScore = 0;
  41.    gameScoreTxt = 0;
  42. }
  43. function fillPopGrid()
  44. {
  45.    var gridWidth = 10;
  46.    var gridHeight = 10;
  47.    var gridSpacing = 23;
  48.    var popSize = 20;
  49.    var xbase = (- (gridWidth - 1) / 2) * gridSpacing;
  50.    var ybase = (- (gridHeight - 1) / 2) * gridSpacing;
  51.    i = 0;
  52.    while(i < gridWidth)
  53.    {
  54.       j = 0;
  55.       while(j < gridHeight)
  56.       {
  57.          var xval = xbase + gridSpacing * i;
  58.          var yval = ybase + gridSpacing * j;
  59.          generatePopper(xval,yval,popSize);
  60.          j++;
  61.       }
  62.       i++;
  63.    }
  64. }
  65. function fillPopWave()
  66. {
  67.    var gridWidth = 10;
  68.    var gridHeight = 10;
  69.    var gridSpacing = 21;
  70.    var popSize = 20;
  71.    var xbase = (- (gridWidth - 1) / 2) * gridSpacing;
  72.    var ybase = (- (gridHeight - 1) / 2) * gridSpacing;
  73.    var xoffset = 0;
  74.    var xradsinc = 0;
  75.    var yoffset = 0;
  76.    var yradsinc = 0;
  77.    i = 0;
  78.    while(i < gridWidth)
  79.    {
  80.       xradsinc = 0;
  81.       j = 0;
  82.       while(j < gridHeight)
  83.       {
  84.          xoffset = Math.sin(xradsinc) * 50;
  85.          var xval = xbase + gridSpacing * i + xoffset;
  86.          var yval = ybase + gridSpacing * j;
  87.          generatePopper(xval,yval,popSize);
  88.          xradsinc += 0.75;
  89.          j++;
  90.       }
  91.       i++;
  92.    }
  93. }
  94. function fillPopRings()
  95. {
  96.    var rings = 5;
  97.    var baseRadius = 23;
  98.    var popSize = 20;
  99.    i = 0;
  100.    while(i < rings)
  101.    {
  102.       var radius = baseRadius + baseRadius * i;
  103.       var pRing = 10 + 5 * i;
  104.       var radSep = 6.283185307179586 / pRing;
  105.       j = 0;
  106.       while(j < pRing)
  107.       {
  108.          var xval = Math.sin(j * radSep) * radius;
  109.          var yval = Math.cos(j * radSep) * radius;
  110.          generatePopper(xval,yval,popSize);
  111.          j++;
  112.       }
  113.       i++;
  114.    }
  115. }
  116. function fillPopSpiro()
  117. {
  118.    var branches = 8;
  119.    var popSize = 20;
  120.    i = 0;
  121.    while(i < branches)
  122.    {
  123.       var radius = 18;
  124.       var pRing = 9;
  125.       var radSep = 2.0734511513692637 / pRing;
  126.       var radOffset = i * (6.283185307179586 / branches);
  127.       var radiusInc = 15;
  128.       j = 0;
  129.       while(j < pRing)
  130.       {
  131.          var xval = Math.sin(radOffset + j * radSep) * radius;
  132.          var yval = Math.cos(radOffset + j * radSep) * radius;
  133.          generatePopper(xval,yval,popSize);
  134.          radius += radiusInc;
  135.          j++;
  136.       }
  137.       i++;
  138.    }
  139. }
  140. function generatePopper(x, y, s)
  141. {
  142.    pcount++;
  143.    popStage.popMaster.duplicateMovieClip("pop" + pcount,pcount + 100);
  144.    thisPop = popStage["pop" + pcount];
  145.    thisPop.food.gotoAndStop(Math.round(Math.random() * 10) + 1);
  146.    thisPop._x = x;
  147.    thisPop._y = y;
  148.    thisPop._width = thisPop._height = s;
  149.    thisPop._visible = false;
  150.    popList.push(thisPop);
  151. }
  152. function popMe()
  153. {
  154.    this._visible = false;
  155.    popsLeft--;
  156.    if(popsLeft == 0)
  157.    {
  158.       finishTime = getTimer();
  159.       gotoAndStop(1);
  160.    }
  161. }
  162. function getAngToPoint(fromX, fromY, toX, toY)
  163. {
  164.    tempXoffset = fromX - toX;
  165.    tempYoffset = toY - fromY;
  166.    var tempAngToPoint = Math.round(Math.atan2(tempXoffset,tempYoffset) * rads) + 180;
  167.    return tempAngToPoint;
  168. }
  169. function atan(mx, my, cx, cy)
  170. {
  171.    dx = mx - cx;
  172.    dy = my - cy;
  173.    at = Math.atan(dy / dx) * 180 / 3.141592653589793;
  174.    if(dx >= 0)
  175.    {
  176.       if(dy >= 0)
  177.       {
  178.          angle = at;
  179.       }
  180.       else
  181.       {
  182.          angle = at + 360;
  183.       }
  184.    }
  185.    if(dx < 0)
  186.    {
  187.       if(dy > 0)
  188.       {
  189.          angle = at + 180;
  190.       }
  191.       else
  192.       {
  193.          angle = at + 180;
  194.       }
  195.    }
  196.    return angle;
  197. }
  198. stop();
  199. _quality = "medium";
  200. globalScale = 80;
  201. stop();
  202. levelBonus = 250;
  203. timeBonus = 10;
  204. sfx = new Array();
  205. sfx[0] = new Sound();
  206. sfx[0].attachSound("bip");
  207. sfx[0].setVolume(25);
  208. sfx[1] = new Sound();
  209. sfx[1].attachSound("pop2");
  210. sfx[1].setVolume(25);
  211. sfx[2] = new Sound();
  212. sfx[2].attachSound("countdown");
  213. sfx[2].setVolume(25);
  214. levels = new Array();
  215. levels.push(new LevelObj(1,0,0,30,100));
  216. levels.push(new LevelObj(2,0,0,30,150));
  217. levels.push(new LevelObj(3,0,0,28,200));
  218. levels.push(new LevelObj(4,0,0,28,250));
  219. levels.push(new LevelObj(1,1,0,26,300));
  220. levels.push(new LevelObj(2,1,0,26,350));
  221. levels.push(new LevelObj(3,1,0,25,400));
  222. levels.push(new LevelObj(4,1,0,25,450));
  223. levels.push(new LevelObj(1,0,1,24,500));
  224. levels.push(new LevelObj(2,0,1,24,550));
  225. levels.push(new LevelObj(3,0,1,23,600));
  226. levels.push(new LevelObj(4,0,1,23,650));
  227. levels.push(new LevelObj(1,3,3,22,700));
  228. levels.push(new LevelObj(2,3,3,22,750));
  229. levels.push(new LevelObj(3,3,3,20,800));
  230. levels.push(new LevelObj(4,3,3,20,850));
  231. currLevel = 0;
  232.